package com.mc2014.util;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

public class Token {
	private String access_Token;
	private Context context;
	
	public Token(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
	}
	public String getAccess_Token() {
		return access_Token;
	}

	public void setAccess_Token(String access_Token) {
		this.access_Token = access_Token;
	}
	public void getAccess_Token_on_Server(String device_key){
		String url = Define_Value.URL+Define_Value.URL_AUTH_TOKEN;
		RequestQueue queue = Volley.newRequestQueue(context);
		Listener<String> listener = new Listener<String>() {

			@Override
			public void onResponse(String response) {
				// TODO Auto-generated method stub
				try {
					JSONObject jobj = new JSONObject(response);
					int code = jobj.getInt(Json_code.JSON_CODE);
					switch (code) {
					case 103:
//						jobj.getString()
						
						break;
					case 104:
						
						break;
					default:
						break;
					}
					
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		};
		ErrorListener errorListener = new ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError error) {
				// TODO Auto-generated method stub
				
			}
		};
		
		StringRequest request = new StringRequest(Method.POST, url, listener , errorListener);
		queue.add(request);
	}
	
	
	
}
